/**
 */
package org.mro.grib.model.files.secondEdition.products.impl;

import java.nio.ByteBuffer;
import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;

import org.mro.grib.model.files.secondEdition.products.ProductDefinitionTemplate430;
import org.mro.grib.model.files.secondEdition.products.ProductsPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Product Definition Template430</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.mro.grib.model.files.secondEdition.products.impl.ProductDefinitionTemplate430Impl#getParameterCategory <em>Parameter Category</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.products.impl.ProductDefinitionTemplate430Impl#getParameterNumber <em>Parameter Number</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.products.impl.ProductDefinitionTemplate430Impl#getTypeOfGeneratingProcess <em>Type Of Generating Process</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.products.impl.ProductDefinitionTemplate430Impl#getObservationGeneratingProcessIdentifier <em>Observation Generating Process Identifier</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.products.impl.ProductDefinitionTemplate430Impl#getNumberOfContributingSpectralBands <em>Number Of Contributing Spectral Bands</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.products.impl.ProductDefinitionTemplate430Impl#getContributingBandOffsets <em>Contributing Band Offsets</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ProductDefinitionTemplate430Impl extends EObjectImpl implements ProductDefinitionTemplate430 {
	/**
	 * The default value of the '{@link #getParameterCategory() <em>Parameter Category</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameterCategory()
	 * @generated
	 * @ordered
	 */
	protected static final byte PARAMETER_CATEGORY_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getParameterCategory() <em>Parameter Category</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameterCategory()
	 * @generated
	 * @ordered
	 */
	protected byte parameterCategory = PARAMETER_CATEGORY_EDEFAULT;

	/**
	 * The default value of the '{@link #getParameterNumber() <em>Parameter Number</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameterNumber()
	 * @generated
	 * @ordered
	 */
	protected static final byte PARAMETER_NUMBER_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getParameterNumber() <em>Parameter Number</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameterNumber()
	 * @generated
	 * @ordered
	 */
	protected byte parameterNumber = PARAMETER_NUMBER_EDEFAULT;

	/**
	 * The default value of the '{@link #getTypeOfGeneratingProcess() <em>Type Of Generating Process</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypeOfGeneratingProcess()
	 * @generated
	 * @ordered
	 */
	protected static final byte TYPE_OF_GENERATING_PROCESS_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getTypeOfGeneratingProcess() <em>Type Of Generating Process</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypeOfGeneratingProcess()
	 * @generated
	 * @ordered
	 */
	protected byte typeOfGeneratingProcess = TYPE_OF_GENERATING_PROCESS_EDEFAULT;

	/**
	 * The default value of the '{@link #getObservationGeneratingProcessIdentifier() <em>Observation Generating Process Identifier</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getObservationGeneratingProcessIdentifier()
	 * @generated
	 * @ordered
	 */
	protected static final byte OBSERVATION_GENERATING_PROCESS_IDENTIFIER_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getObservationGeneratingProcessIdentifier() <em>Observation Generating Process Identifier</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getObservationGeneratingProcessIdentifier()
	 * @generated
	 * @ordered
	 */
	protected byte observationGeneratingProcessIdentifier = OBSERVATION_GENERATING_PROCESS_IDENTIFIER_EDEFAULT;

	/**
	 * The default value of the '{@link #getNumberOfContributingSpectralBands() <em>Number Of Contributing Spectral Bands</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNumberOfContributingSpectralBands()
	 * @generated
	 * @ordered
	 */
	protected static final byte NUMBER_OF_CONTRIBUTING_SPECTRAL_BANDS_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getNumberOfContributingSpectralBands() <em>Number Of Contributing Spectral Bands</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNumberOfContributingSpectralBands()
	 * @generated
	 * @ordered
	 */
	protected byte numberOfContributingSpectralBands = NUMBER_OF_CONTRIBUTING_SPECTRAL_BANDS_EDEFAULT;

	/**
	 * The cached value of the '{@link #getContributingBandOffsets() <em>Contributing Band Offsets</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getContributingBandOffsets()
	 * @generated
	 * @ordered
	 */
	protected EList<Long> contributingBandOffsets;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProductDefinitionTemplate430Impl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ProductsPackage.Literals.PRODUCT_DEFINITION_TEMPLATE430;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getParameterCategory() {
		return parameterCategory;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParameterCategory(byte newParameterCategory) {
		byte oldParameterCategory = parameterCategory;
		parameterCategory = newParameterCategory;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_CATEGORY, oldParameterCategory, parameterCategory));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getParameterNumber() {
		return parameterNumber;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParameterNumber(byte newParameterNumber) {
		byte oldParameterNumber = parameterNumber;
		parameterNumber = newParameterNumber;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_NUMBER, oldParameterNumber, parameterNumber));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getTypeOfGeneratingProcess() {
		return typeOfGeneratingProcess;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTypeOfGeneratingProcess(byte newTypeOfGeneratingProcess) {
		byte oldTypeOfGeneratingProcess = typeOfGeneratingProcess;
		typeOfGeneratingProcess = newTypeOfGeneratingProcess;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__TYPE_OF_GENERATING_PROCESS, oldTypeOfGeneratingProcess, typeOfGeneratingProcess));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getObservationGeneratingProcessIdentifier() {
		return observationGeneratingProcessIdentifier;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setObservationGeneratingProcessIdentifier(byte newObservationGeneratingProcessIdentifier) {
		byte oldObservationGeneratingProcessIdentifier = observationGeneratingProcessIdentifier;
		observationGeneratingProcessIdentifier = newObservationGeneratingProcessIdentifier;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__OBSERVATION_GENERATING_PROCESS_IDENTIFIER, oldObservationGeneratingProcessIdentifier, observationGeneratingProcessIdentifier));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getNumberOfContributingSpectralBands() {
		return numberOfContributingSpectralBands;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setNumberOfContributingSpectralBands(byte newNumberOfContributingSpectralBands) {
		byte oldNumberOfContributingSpectralBands = numberOfContributingSpectralBands;
		numberOfContributingSpectralBands = newNumberOfContributingSpectralBands;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__NUMBER_OF_CONTRIBUTING_SPECTRAL_BANDS, oldNumberOfContributingSpectralBands, numberOfContributingSpectralBands));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Long> getContributingBandOffsets() {
		if (contributingBandOffsets == null) {
			contributingBandOffsets = new EDataTypeUniqueEList<Long>(Long.class, this, ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__CONTRIBUTING_BAND_OFFSETS);
		}
		return contributingBandOffsets;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_CATEGORY:
				return getParameterCategory();
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_NUMBER:
				return getParameterNumber();
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__TYPE_OF_GENERATING_PROCESS:
				return getTypeOfGeneratingProcess();
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__OBSERVATION_GENERATING_PROCESS_IDENTIFIER:
				return getObservationGeneratingProcessIdentifier();
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__NUMBER_OF_CONTRIBUTING_SPECTRAL_BANDS:
				return getNumberOfContributingSpectralBands();
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__CONTRIBUTING_BAND_OFFSETS:
				return getContributingBandOffsets();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_CATEGORY:
				setParameterCategory((Byte)newValue);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_NUMBER:
				setParameterNumber((Byte)newValue);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__TYPE_OF_GENERATING_PROCESS:
				setTypeOfGeneratingProcess((Byte)newValue);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__OBSERVATION_GENERATING_PROCESS_IDENTIFIER:
				setObservationGeneratingProcessIdentifier((Byte)newValue);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__NUMBER_OF_CONTRIBUTING_SPECTRAL_BANDS:
				setNumberOfContributingSpectralBands((Byte)newValue);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__CONTRIBUTING_BAND_OFFSETS:
				getContributingBandOffsets().clear();
				getContributingBandOffsets().addAll((Collection<? extends Long>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_CATEGORY:
				setParameterCategory(PARAMETER_CATEGORY_EDEFAULT);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_NUMBER:
				setParameterNumber(PARAMETER_NUMBER_EDEFAULT);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__TYPE_OF_GENERATING_PROCESS:
				setTypeOfGeneratingProcess(TYPE_OF_GENERATING_PROCESS_EDEFAULT);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__OBSERVATION_GENERATING_PROCESS_IDENTIFIER:
				setObservationGeneratingProcessIdentifier(OBSERVATION_GENERATING_PROCESS_IDENTIFIER_EDEFAULT);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__NUMBER_OF_CONTRIBUTING_SPECTRAL_BANDS:
				setNumberOfContributingSpectralBands(NUMBER_OF_CONTRIBUTING_SPECTRAL_BANDS_EDEFAULT);
				return;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__CONTRIBUTING_BAND_OFFSETS:
				getContributingBandOffsets().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_CATEGORY:
				return parameterCategory != PARAMETER_CATEGORY_EDEFAULT;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__PARAMETER_NUMBER:
				return parameterNumber != PARAMETER_NUMBER_EDEFAULT;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__TYPE_OF_GENERATING_PROCESS:
				return typeOfGeneratingProcess != TYPE_OF_GENERATING_PROCESS_EDEFAULT;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__OBSERVATION_GENERATING_PROCESS_IDENTIFIER:
				return observationGeneratingProcessIdentifier != OBSERVATION_GENERATING_PROCESS_IDENTIFIER_EDEFAULT;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__NUMBER_OF_CONTRIBUTING_SPECTRAL_BANDS:
				return numberOfContributingSpectralBands != NUMBER_OF_CONTRIBUTING_SPECTRAL_BANDS_EDEFAULT;
			case ProductsPackage.PRODUCT_DEFINITION_TEMPLATE430__CONTRIBUTING_BAND_OFFSETS:
				return contributingBandOffsets != null && !contributingBandOffsets.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (parameterCategory: "); //$NON-NLS-1$
		result.append(parameterCategory);
		result.append(", parameterNumber: "); //$NON-NLS-1$
		result.append(parameterNumber);
		result.append(", typeOfGeneratingProcess: "); //$NON-NLS-1$
		result.append(typeOfGeneratingProcess);
		result.append(", observationGeneratingProcessIdentifier: "); //$NON-NLS-1$
		result.append(observationGeneratingProcessIdentifier);
		result.append(", numberOfContributingSpectralBands: "); //$NON-NLS-1$
		result.append(numberOfContributingSpectralBands);
		result.append(", contributingBandOffsets: "); //$NON-NLS-1$
		result.append(contributingBandOffsets);
		result.append(')');
		return result.toString();
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.secondEdition.products.IProductDefinition#initialise(java.nio.ByteBuffer)
	 */
	@Override
	public void initialise(ByteBuffer buffer) {
		parameterCategory = buffer.get();
		parameterNumber = buffer.get();
		typeOfGeneratingProcess = buffer.get();
		observationGeneratingProcessIdentifier = buffer.get();
		numberOfContributingSpectralBands = buffer.get();
		for(int i = 1 ; i < numberOfContributingSpectralBands + 1 ; i++)
		{
			contributingBandOffsets.add(Long.valueOf(buffer.position() + 10 * (i -1))); 
		}
	}
	
} //ProductDefinitionTemplate430Impl
